<template>
  <div class="form-card">
    <div class="form-title">
      <i class="fas fa-stethoscope form-icon"></i>
      <h2>选择一级科室</h2>
    </div>

    <div class="form-description">
      <p>请选择您要就诊的一级科室：</p>
    </div>

    <div class="departments-grid">
      <div
        class="department-card"
        v-for="department in primaryDepartments"
        :key="department.id"
        :class="{selected: formData.primaryDepartmentId === department.id}"
        @click="selectDepartment(department.id)"
      >
        <div class="department-icon">
          <i :class="department.icon"></i>
        </div>
        <div class="department-info">
          <h3>{{ department.name }}</h3>
          <p>{{ department.description }}</p>
        </div>
        <div class="checkmark" v-if="formData.primaryDepartmentId === department.id">
          <i class="fas fa-check-circle"></i>
        </div>
      </div>
    </div>

    <div class="form-buttons">
      <button type="button" class="btn btn-secondary" @click="goToPreviousStep">
        <i class="fas fa-arrow-left"></i>
        上一步
      </button>
      <button type="button" class="btn btn-primary" :disabled="!formData.primaryDepartmentId" @click="goToNextStep">
        下一步
        <i class="fas fa-arrow-right"></i>
      </button>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const props = defineProps({
  modelValue: {
    type: Object,
    required: true
  }
})

const emit = defineEmits(['update:modelValue', 'previous', 'next'])

const formData = ref({
  primaryDepartmentId: props.modelValue.primaryDepartmentId || null
})

const primaryDepartments = [
  { id: 1, name: '内科', icon: 'fas fa-stethoscope', description: '涵盖呼吸、消化、心血管等内科疾病诊疗' },
  { id: 2, name: '外科', icon: 'fas fa-syringe', description: '开展各类外科手术及外科疾病治疗' },
  { id: 3, name: '妇产科', icon: 'fas fa-baby-carriage', description: '妇科疾病诊治及产科孕产全程服务' },
  { id: 4, name: '男科', icon: 'fas fa-user-md', description: '男性生殖系统及相关疾病诊疗' },
  { id: 5, name: '儿科', icon: 'fas fa-child', description: '针对儿童各系统疾病的专业诊疗' },
  { id: 6, name: '五官科', icon: 'fas fa-eye', description: '眼、耳、鼻、喉及口腔疾病综合诊疗' },
  { id: 7, name: '肿瘤科', icon: 'fas fa-heartbeat', description: '肿瘤预防、诊断及综合治疗' },
  { id: 8, name: '皮肤性病科', icon: 'fas fa-allergies', description: '皮肤病与性传播疾病诊治' },
  { id: 9, name: '中医科', icon: 'fas fa-leaf', description: '中医辨证施治及传统疗法干预' },
  { id: 10, name: '传染科', icon: 'fas fa-shield-virus', description: '各类传染性疾病的诊治与防控' },
  { id: 11, name: '精神心理科', icon: 'fas fa-brain', description: '精神心理疾病诊疗与心理干预' }
]

const selectDepartment = (departmentId) => {
  formData.value.primaryDepartmentId = departmentId
}

const goToPreviousStep = () => {
  emit('previous')
}

const goToNextStep = () => {
  if (!formData.value.primaryDepartmentId) {
    alert('请先选择一级科室！')
    return
  }
  
  // Emit updated form data to parent
  emit('update:modelValue', { 
    ...props.modelValue, 
    primaryDepartmentId: formData.value.primaryDepartmentId 
  })
  
  emit('next')
}
</script>

<style scoped>
.form-card {
  background-color: white;
  border-radius: 16px;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
  padding: 30px;
  margin-bottom: 30px;
}

.form-title {
  display: flex;
  align-items: center;
  margin-bottom: 30px;
  border-bottom: 2px solid #f0f0f0;
  padding-bottom: 20px;
}

.form-icon {
  font-size: 32px;
  color: #3498db;
  margin-right: 15px;
}

.form-title h2 {
  font-size: 28px;
  font-weight: 700;
  color: #2980b9;
  margin: 0;
}

.form-description {
  margin-bottom: 25px;
}

.form-description p {
  font-size: 20px;
  color: #555;
  margin: 0;
}

.departments-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.department-card {
  display: flex;
  align-items: center;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  padding: 20px;
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
  background: white;
}

.department-card:hover {
  border-color: #5dade2;
  transform: translateY(-3px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
}

.department-card.selected {
  border-color: #3498db;
  background-color: rgba(52, 152, 219, 0.05);
}

.department-icon {
  font-size: 32px;
  color: #3498db;
  margin-right: 15px;
  width: 50px;
  text-align: center;
}

.department-info h3 {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 5px 0;
  color: #333;
}

.department-info p {
  font-size: 18px;
  color: #666;
  margin: 0;
}

.checkmark {
  position: absolute;
  top: 15px;
  right: 15px;
  color: #2ecc71;
  font-size: 24px;
}

.form-buttons {
  display: flex;
  justify-content: space-between;
  margin-top: 40px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 30px;
  font-size: 20px;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s;
  min-width: 160px;
}

.btn i {
  margin: 0 8px;
}

.btn-primary {
  background-color: #3498db;
  color: white;
}

.btn-primary:hover {
  background-color: #2980b9;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.btn-primary:disabled {
  background-color: #bdc3c7 !important;
  border-color: #bdc3c7 !important;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background-color: #e0e0e0;
  color: #555;
}

.btn-secondary:hover {
  background-color: #d0d0d0;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.btn-secondary:disabled {
  background-color: #f0f0f0;
  color: #aaa;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .form-card {
    padding: 20px;
  }

  .form-title h2 {
    font-size: 24px;
  }

  .form-icon {
    font-size: 28px;
  }

  .form-description p {
    font-size: 18px;
  }

  .departments-grid {
    grid-template-columns: 1fr;
  }

  .department-card {
    padding: 15px;
  }

  .department-info h3 {
    font-size: 20px;
  }

  .department-info p {
    font-size: 16px;
  }

  .btn {
    padding: 14px 20px;
    font-size: 18px;
    min-width: 120px;
  }

  .form-buttons {
    flex-direction: column;
    gap: 15px;
  }

  .form-buttons .btn {
    width: 100%;
  }
}
</style>